package com.steven.string;

public class StringTest2 {
	
	public static void main(String[] args) {
		String source="aabbccaabbdddaabbadfaaddddaadddesf";
		String searchKey="aa";
		
		
		System.out.println("count:"+getCount2(source,searchKey));
		
	}

	private static int getCount(String source, String searchKey) {
	 
		int count=0;
		int index =0;
		 while((index =source.indexOf(searchKey,index))!=-1){
			 System.out.println(index);
			 index+=searchKey.length();
			
			 count++;
			 
			 
		 }
		
		return count;
	}

	private static int getCount2(String source, String searchKey) {
		 
		int count=0;
		int index =0;
		 while((index =source.indexOf(searchKey))!=-1){
			 System.out.println(index);
			 
			 index+=searchKey.length();
			 source=source.substring(index);
			
			 count++;
			 
			 
		 }
		
		return count;
	}
 

}
